#ifndef YIGMAINWINDOW_H
#define YIGMAINWINDOW_H

// System includes
#include <QMainWindow>
#include <QLabel>
#include <QListWidget>
#include <QDockWidget>
#include <QToolButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QCheckBox>
#include <QSpinBox>
#include <QLineEdit>

// Local includes
#include "gui/yiggraphicsview.h"
#include "gui/yignetworkchannelview.h"


/**
*   @class YigOptionsWindow where the options for yig can be changed
*/
class YigOptionsWindow : public QWidget
{
    Q_OBJECT

public:

    explicit YigOptionsWindow(QWidget* mainWindow, QWidget* parent = 0);
    ~YigOptionsWindow();

signals:

    void toggleAudioPipe(bool pipingAudio, QString audioPipeIP, int audioPipePort);

private slots:

    void setAudioPipeBool(bool pipingAudio);
    void setAudioPipePort(int audioPipePort);
    void setAudioPipeIP();

private:

    QVBoxLayout layout;
    QHBoxLayout audioPipeLayout;
    QSpinBox pipePortEntry;
    QLineEdit pipeIpEntry;
    QCheckBox animationCheckBox, audioPipeCheckBox;
    QWidget* mMainWindow;
    bool mAudioPiping;
    int mAudioPipePort;
    QString mAudioPipeIP;
};

/**
*   @class Main window in which all gui elements reside
*/
class YigMainWindow : public QWidget
{
    Q_OBJECT

public:

    /**
    *   YigMainWindow Constructor
    *   @param QWidget* Parent widget. Since this is the main window, there is no parent
    */
    explicit YigMainWindow(QWidget* parent = 0);

    /**
    * YigMainWindow deconstructor, cleans up our channelViewList pointers.
    */
    ~YigMainWindow();

    /**
    *   setActiveChannel activates the given channel, and deactives all others (pertaining to drop status and interactivity)
    *   @param int channelNum The number of the channel in the channelViewArray that will be active
    */
    void setActiveChannel(int channelNum);

    /**
    *   returns a pointer to the graphics view
    *   @param YigNetworkChannelView* The pointer to the graphics view
    */
    YigNetworkChannelView* getGraphicsView();

signals:

    /** emitted when we want to start/top the animation of the oscilloscopes and cables */
    void toggleGraphicsAnimation(bool animatingGraphics);

    /** emitted when we want to send the stereo output of scsynth to a system pipeline, fore external visualization */
    void toggleAudioPipe(bool pipingAudio, QString audioPipeIP, int audioPipePort);

    /** emitted when the user begins/ends recording */
    void recording(bool recording);

    /** emitted when the user begins/ends networking */
    void networking(bool networking);

public slots:

    /**
    *   updates the main window with the current server status
    *   @param QString The current boot status of the sc synth server: "inactive", "booting", or "running"
    *   @param int The current number of synths running on the server
    *   @param float The average CPU taken up by the server
    *   @param float The Peak CPU taken up by the server
    */
    void updateServerStatus(QString serverBootStatus, int numSynths, float avgCPU, float peakCPU);

    /**
    *   addUser adds a user to the currentUsers gui element
    *   @param QString the screen name of the user to add
    */
    void addUser(QString userName);

    /**
    *   removeUser removes a user to the currentUsers gui element
    *   @param QString the screen name of the user to remove
    */
    void removeUser(QString userName);


private slots:

    /** called by the record button, and begins/stops recording */
    void record();

    /** called by connect button, begins/ends networking */
    void networkConnection();

    /** opens the options window for Yig */
    void toggleOptionsWindow();

protected:

    /** overridden to create auto chat ability */
    //void keyPressEvent(QKeyEvent *e);

    /** overridden to pass resizing on to the child views */
    void resizeEvent(QResizeEvent *e);

private:

    ///** fixed array of NetworkChannelViews */
    //QList<YigNetworkChannelView*> channelViewList;
    /** displays the graphics! */
    YigNetworkChannelView graphicsView;
    /** color for the mainView background */
    QColor backgroundColor;
    /** brush for the mainView background */
    QBrush backgroundBrush;
    /** labels for displaying information about the running server */
    QLabel* bootStatus;
    /** displays the current number of synths running on the server */
    QLabel* numberOfSynths;
    /** displays the average CPU taken up by scsynth */
    QLabel* avgCPU;
    /** displays the peak CPU taken up by scsynth */
    QLabel* peakCPU;
    /** begins/finishes recordings in Yig */
    QToolButton* recordButton;
    /** starts/ends osc networking */
    QToolButton* connectButton;
    /** opens the options menu for starting/stopping graphics and sending audio output to an external pipe */
    QToolButton* optionsButton;
    /** list widget that displays the current users */
    QListWidget* currentUsers;
    /** label next to the currentUsers QListWidget */
    QLabel* currentUsersLabel;
    /** displays information about users and the scsynth server */
    QWidget* toolBar;
    QDockWidget dock;
    QWidget* titleBarWidget;
    /** boolean indicating the online status of the gui */
    bool mOnline;
    /** window containing the relavent options available for yig */
    YigOptionsWindow* optionsWindow;
};

#endif // YIGMAINWINDOW_H
